<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户列表页面</title>
<%@ include file="../common/common_include.jsp"%>

<script type="text/javascript">
/**
 * 功能：短信投票统计 date：2011-11-07 author: zhangzhijian
 */
Ext.onReady(function() {
var searchPanel = new Ext.FormPanel({
	formId:'testForm',
    region: 'north',
    collapsible: true,
    title: '查询条件设置',
    // TODO：国际化
    split: true,
    frame: true,
    height: 150,
    layout: 'form',
    bodyStyle: 'padding:10px;',
    defaults: {
        border: false
    },
    items: [{
        layout: 'column',
        defaults: {
            border: false
        },
        style: 'padding-left:5px',
        items: [
        {
            columnWidth: 0.3,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'textfield',
                fieldLabel: '用户昵称',
                // TODO:国际化
                id: 'petName',
                ctCls: 'input-label-padding',
                labelStyle: 'width:70px',
                width: 210
            }]
        },{
            columnWidth: 0.35,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'datefield',
                fieldLabel: '注册起始时间',
                // TODO：国际化
                id: 'createTimeStart',
                format: 'Y-m-d',
                ctCls: 'input-label-padding',
                labelStyle: 'width:80px',
                width: 210,
                editable: false
            }]
        },
        {
            columnWidth: 0.35,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'datefield',
                fieldLabel: '注册结束时间',
                // TODO：国际化
                id: 'createTimeEnd',
                format: 'Y-m-d',
                ctCls: 'input-label-padding',
                labelStyle: 'width:80px',
                width: 210,
                editable: false
            }]
        }]
    },
    {
        layout: 'column',
        defaults: {
            border: false
        },
        style: 'padding-left:5px',
        items: [{
            columnWidth: 0.3,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'textfield',
                fieldLabel: '用户邮箱',
                // TODO：国际化
                id: 'email',
                ctCls: 'input-label-padding',
                labelStyle: 'width:70px',
                width: 210,
                editable: false
            }]
        },
        {
            columnWidth: 0.35,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'combo',
                fieldLabel: '用户类型',
                id: 'type',
                ctCls: 'input-label-padding',
                labelStyle: 'width:80px',
                width: 210,
                editable: false,
                valueField: 'retrunValue',
    			mode: 'local',
    	        displayField: "displayText",
    	        triggerAction: 'all',
    	        value:'',
    			store: new Ext.data.SimpleStore({
    			    fields: ["retrunValue", "displayText"],
    			    data: [['', '全部'],['0', '注册会员'],['1', '管理员']]
    			})
            }]
        },
        {
            columnWidth: 0.35,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'combo',
                fieldLabel: '是否激活',
                // TODO:国际化
                id: 'isActive',
                ctCls: 'input-label-padding',
                labelStyle: 'width:80px',
                editable: false,
                width: 210,
                valueField: 'retrunValue',
    			mode: 'local',
    	        displayField: "displayText",
    	        triggerAction: 'all',
    	        value:'',
    			store: new Ext.data.SimpleStore({
    			    fields: ["retrunValue", "displayText"],
    			    data: [['', '全部'],['0', '未激活'],['1', '已激活']]
    			})
            }]
        }]
    },
    {
        layout: 'column',
        defaults: {
            border: false
        },
        items: [{
            columnWidth: .85,
            layout: 'form',
            defaults: {
                border: false
            },
            style: 'padding-left:780px',
            items: [{
                xtype: 'button',
                text: '查&nbsp;&nbsp;&nbsp;询',
                width: 80,
                handler: function() {
                	searchFunc();
                }
            }]
        },
        {
            columnWidth: .12,
            layout: 'form',
            defaults: {
                border: false
            },
            items: [{
                xtype: 'button',
                text: '重&nbsp;&nbsp;&nbsp;置',
                width: 80,
                handler: function() {
                    searchPanel.getForm().reset();
                }
            }]
        }]
    }]
}); 

// 生成Toolbar
var toolbar = new Ext.Toolbar({
    id: '_toolbar',
    height: 25,
    items: [{
        text: '激活帐号',
        handler: function() {
        	updaeFunc('您确定要激活选中的帐号?',null,1,null,function(res){
        		Ext.Msg.alert('成功','激活帐号成功!');
        		Ext.getCmp('gdList').getStore().reload();
        	},function(){
				Ext.Msg.alert('失败','激活帐号失败，请重试!');        		
        	});       	
        }
    },
    '-', {
        text: '帐号失效',
        handler: function() {
        	updaeFunc('您确定要将选中的帐号置为未激活状态?',null,0,null,function(res){
        		Ext.Msg.alert('成功','置帐号为为激活状态成功!');
        		Ext.getCmp('gdList').getStore().reload();
        	},function(){
				Ext.Msg.alert('失败','置帐号为为激活状态失败，请重试!');        		
        	}); 
        }
    },
    '-', {
        text: '设为管理员',
        handler: function() {
        	updaeFunc('您确定要将选中的帐号置为管理员?',1,null,null,function(res){
        		Ext.Msg.alert('成功','置管理员成功!');
        		Ext.getCmp('gdList').getStore().reload();
        	},function(){
				Ext.Msg.alert('失败','置管理员失败，请重试!');        		
        	}); 
        }
    },
    '-', {
        text: '去除管理员',
        handler: function() {
        	updaeFunc('您确定要将选中的帐号置为非管理员?',0,null,null,function(res){
        		Ext.Msg.alert('成功','置非管理员成功!');
        		Ext.getCmp('gdList').getStore().reload();
        	},function(){
				Ext.Msg.alert('失败','置非管理员失败，请重试!');        		
        	}); 
        }
    },
    '-', {
        text: '重置密码',
        handler: function() {
        	updaeFunc('您确定要将选中的帐号重置密码?',null,null,1,function(res){
        		Ext.Msg.alert('成功','重置帐号成功!');
        		Ext.getCmp('gdList').getStore().reload();
        	},function(){
				Ext.Msg.alert('失败','重置帐号失败，请重试!');        		
        	}); 
        }
    }]
}); 

// 配置JsonStore
var gridStore = new Ext.data.JsonStore({
    url: './bg_bguser_loadUserList.htm',
    totalProperty: "sum",
    remoteSort: true,
    root: "root",
    fields: [{
        mapping: 'userId',
        name: 'USER_ID'
    },
    {
        mapping: 'petName',
        name: 'PET_NAME'
    },
    {
        mapping: 'addr',
        name: 'ADDR'
    },
    {
        mapping: 'school',
        name: 'SCHOOL'
    },
    {
        mapping: 'email',
        name: 'EMAIL'
    },
    {
        mapping: 'type',
        name: 'TYPE'
    },
    {
        mapping: 'createTime',
        name: 'CREATE_TIME'
    },
    {
        mapping: 'relName',
        name: 'REL_NAME'
    },
    {
        mapping: 'isActive',
        name: 'IS_ACTIVE'
    }]
});
var AllChk = new Ext.grid.CheckboxSelectionModel({
    checkOnly: true,
    dataIndex: 'id'
}); // 生成数据列表
var grid = new Ext.grid.GridPanel({
    id: 'gdList',
    region: 'center',
    store: gridStore,
    layout: 'fit',
    // autoHeight : true,
    tbar: toolbar,
    sm: AllChk,
    loadMask: {
        msg: '数据加载中...'
    },
    columns: [AllChk, {
        header: '用户昵称',
        width: 150,
        sortable: false,
        dataIndex: 'PET_NAME'
    },
    {
        header: '真实姓名',
        width: 160,
        sortable: false,
        dataIndex: 'REL_NAME'
    },
    {
        header: '学校',
        width: 240,
        sortable: false,
        dataIndex: 'SCHOOL'
    },
    {
        header: '邮箱',
        width: 160,
        dataIndex: 'EMAIL'
    },
    {
        header: '注册时间',
        width: 160,
        sortable: true,
        dataIndex: 'CREATE_TIME'
    },
    {
        header: '是否激活',
        width: 80,
        sortable: false,
        dataIndex: 'IS_ACTIVE',
        renderer:function(value) {
        	return value == 0 ? '未激活':'已激活';
        }
    },
    {
        header: '用户类型',
        width: 80,
        sortable: false,
        dataIndex: 'TYPE',
        renderer:function(value,p,record){
        	return value == 0 ? '注册会员' : '管理员'
        }
    }],
    bbar: new Ext.PagingToolbar({
        id: 'gridBbar',
        pageSize: 20,
        store: gridStore,
        displayInfo: true,
        doRefresh: function() {
            gridStore.reload();
        }
    })
});
gridStore.load({
    params: {
        start: 0,
        limit: 20
    }
});
var viewport = new Ext.Viewport({
    layout: 'border',
    items: [searchPanel, grid]
}); // 定义查询按键事件
var searchFunc = function() {
    gridStore.baseParams = {
        'userForm.petName': Ext.getDom('petName').value,
        'userForm.createTimeStart': Ext.getDom('createTimeStart').value,
        'userForm.createTimeEnd': Ext.getDom('createTimeEnd').value,
        'userForm.email': Ext.getDom('email').value,
        'userForm.type': Ext.getCmp('type').getValue(),
        'userForm.isActive': Ext.getCmp('isActive').getValue()
    };
    gridStore.load({
        params: {
            start: 0,
            limit: 50
        }
    });
};

var updaeFunc = function(tipMsg,type,isActive,resetPassword,sucFunc, failFunc) {
	var selIds = com.tietiao.getSelectedGridValue(AllChk,'USER_ID');
	if(selIds == null || selIds.length == 0) {
		 dhcc.portal.messagebox.warning('请选择所需要操作的数据!');
		 return ;
	}
	Ext.Msg.confirm('系统提示',tipMsg,function(btn,text){
		 if(btn == 'yes') {
			 Ext.Ajax.request({
		         url: './bg_bguser_updateStates.htm',
		         // 请求的服务器地址
		         params: {
		             'userForm.userIds': selIds,
		             'userForm.isActive':isActive == null ? '' : isActive,
		             'userForm.type': type == null ? '' : type,
		             'userForm.resetPassword': resetPassword == null ? '': resetPassword
		         },
		         // 请求参数
		         method: 'POST',
		         success: sucFunc,
		         failure: failFunc
		     });
		 }
	 });
	return ;
  };
});	
</script>
</head>
<body>

</body>
</html>